-
Notifications
You must be signed in to change notification settings - Fork 331
Ensuring that flush() will raise on rollback if called from change/0. #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/ecto/migration.ex
Outdated
| Runner.flush | ||
| @doc "Executes queue migration commands." | ||
| defmacro flush do | ||
| quote bind_quoted: [caller: __CALLER__.module] do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need bind_quoted, the module inside the quote will be __MODULE__.
lib/ecto/migration.ex
Outdated
| @doc "Executes queue migration commands." | ||
| defmacro flush do | ||
| quote bind_quoted: [caller: __CALLER__.module] do | ||
| if direction() == :down and function_exported?(caller, :change, 0) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migrator checks for down first and then falls back to :change, so we should express this here:
| if direction() == :down and function_exported?(caller, :change, 0) do | |
| if direction() == :down and not function_exported?(caller, :down, 0) do |
lib/ecto/migration.ex
Outdated
| defmacro flush do | ||
| quote bind_quoted: [caller: __CALLER__.module] do | ||
| if direction() == :down and function_exported?(caller, :change, 0) do | ||
| message = "Calling flush() inside change when doing rollback is not supported." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages start with lowercase:
| message = "Calling flush() inside change when doing rollback is not supported." | |
| message = "calling flush() inside change when doing rollback is not supported." |
lib/ecto/migration.ex
Outdated
| quote bind_quoted: [caller: __CALLER__.module] do | ||
| if direction() == :down and function_exported?(caller, :change, 0) do | ||
| message = "Calling flush() inside change when doing rollback is not supported." | ||
| raise ArgumentError, message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an ArgumentError in this case, so this is enough:
| raise ArgumentError, message | |
| raise message |
|
Thanks @Eiji7, I have dropped some comments. Also, instead of adding an integration test, can you please add a unit test? See test/ecto/migrator_test.exs. |
1. Use __MODULE__ inside quote instead of __CALLER__ in bind_quoted 2. Fix check in if 3. Changed error message to start with lowercase 4. Use raise/1 instead of raise/2 with ArgumentError 5. Moved test from integration_test/sql/migration.ex to test/ecto/migrator_test.exs
|
@josevalim Thanks, everything makes sense for me. I have send all suggested changes as well as moved test. |
|
❤️ 💚 💙 💛 💜 |
ping @josevalim